import request from 'utils/request'

/**
 * 获取文章列表
 * @param {*} query 筛选文章参数
 * @returns Promise
 */
export const getArticlesAPI = (query) => {
  return request({
    url: '/v1_0/mp/articles',
    method: 'get',
    params: query,
  })
}

/**
 * 删除文章
 * @param {string} id 根据id删除文章
 * @returns Promise
 */
export const deleteArticleByIdAPI = (id) => {
  return request({
    url: `/v1_0/mp/articles/${id}`,
    method: 'DELETE',
  })
}

/**
 * 发表文章
 * @param {Object} 发布文章所有参数
 * @returns Promise
 */
export const publishArticleAPI = ({ draft = false, ...body }) => {
  return request({
    url: `/v1_0/mp/articles?draft=${draft}`,
    method: 'POST',
    data: body,
  })
}

/**
 * 获取文章详情
 * @param {id} 文章 id
 * @returns Promise
 */
export const getArticleByIdAPI = (id) => {
  return request({
    url: `/v1_0/mp/articles/${id}`,
    method: 'GET',
  })
}

/**
 * 编辑文章
 * @param {*} 编辑文章所有参数
 * @returns Promise
 */
export const eidtArticleAPI = ({ draft = false, id, ...body }) => {
  return request({
    url: `/v1_0/mp/articles/${id}?draft=${draft}`,
    method: 'PUT',
    data: body,
  })
}
